﻿#pragma once

#include "../../MirObjects/Effect.h"
#include "../../MirControls/MirImageControl.h"
#include "../../MirControls/MirLabel.h"
#include "../../MirControls/MirButton.h"
#include "../../../Shared/Data/GuildData.h"
#include "../../../Shared/Enums.h"
#include "../../MirControls/MirTextBox.h"
#include "../../../Shared/Data/Notice.h"
#include "../../MirControls/MirDropDownBox.h"
#include "../../MirControls/MirItemCell.h"
#include "../../MirControls/MirControl.h"
#include <string>
#include <vector>
#include <cmath>
#include <limits>
#include <any>
#include "../../../bankersrounding.h"
#include "../../../stringhelper.h"

//C# TO C++ CONVERTER NOTE: Forward class declarations:
namespace Client::MirScenes::Dialogs { class GuildBuffButton; }

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirObjects;
using namespace Client::MirSounds;
using namespace SlimDX::Direct3D9;
//C# TO C++ CONVERTER TODO TASK: C# to C++ Converter could not confirm whether this is a namespace alias or a type alias:
//using Font = System::Drawing::Font;
namespace S = ServerPackets;
namespace C = ClientPackets;

using namespace Client::MirScenes::Dialogs;

namespace Client::MirScenes::Dialogs
{

    class GuildDialog final : public MirImageControl
    {
        #pragma region NoticeBase
    public:
        MirLabel *GuildName;
        MirButton *CloseButton;
        #pragma endregion

        #pragma region GuildLeft
        MirButton *NoticeButton, *MembersButton, *StorageButton, *RankButton;
        MirImageControl *NoticePage, *MembersPage, *StoragePage, *RankPage;
        MirImageControl *StoragePageBase, *MembersPageBase;
        MirImageControl *TitleLabel;
        #pragma endregion

        #pragma region GuildRight
        MirButton *BuffButton, *StatusButton;
        MirImageControl *BuffPage, *StatusPage, *StatusPageBase;

        std::vector<GuildBuffButton*> Buffs;
    private:
        bool RequestedList = false;
    public:
        std::vector<GuildBuffInfo*> GuildBuffInfos = std::vector<GuildBuffInfo*>();
        std::vector<GuildBuff*> EnabledBuffs = std::vector<GuildBuff*>();
        int StartIndex = 0;
    private:
        long long LastRequest = 0;

    public:
        std::string ActiveStats = "";
        #pragma endregion

        #pragma region DataValues
        unsigned char Level = 0;
        long long Experience = 0;
        long long MaxExperience = 0;
        unsigned int Gold = 0;
        unsigned char SparePoints = 0;
        int MemberCount = 0;
        int MaxMembers = 0;
        bool Voting = false;
        unsigned char ItemCount = 0;
        unsigned char BuffCount = 0;
        static int MyRankId;
        static GuildRankOptions MyOptions;
        std::vector<GuildRank*> Ranks = std::vector<GuildRank*>();
        bool MembersChanged = true;
        long long LastMemberRequest = 0;
        long long LastGuildMsg = 0;
        long long LastRankNameChange = 0;
        virtual ~GuildDialog()
        {
            delete GuildName;
            delete CloseButton;
            delete NoticeButton;
            delete MembersButton;
            delete StorageButton;
            delete RankButton;
            delete NoticePage;
            delete MembersPage;
            delete StoragePage;
            delete RankPage;
            delete StoragePageBase;
            delete MembersPageBase;
            delete TitleLabel;
            delete BuffButton;
            delete StatusButton;
            delete BuffPage;
            delete StatusPage;
            delete StatusPageBase;
            delete NoticeUpButton;
            delete NoticeDownButton;
            delete NoticePositionBar;
            delete NoticeEditButton;
            delete NoticeSaveButton;
            delete Notice;
            delete MembersUpButton;
            delete MembersDownButton;
            delete MembersPositionBar;
            delete MembersHeaderRank;
            delete MembersHeaderName;
            delete MembersHeaderStatus;
            delete MembersShowOffline;
            delete MembersShowOfflineButton;
            delete MembersShowOfflineStatus;
            delete StatusLevelLabel;
            delete StatusHeaders;
            delete StatusGuildName;
            delete StatusLevel;
            delete StatusMembers;
            delete StatusExpBar;
            delete StatusExpLabel;
            delete RecruitMemberLabel;
            delete MembersRecruitName;
            delete RecruitMemberButton;
            delete StorageGoldText;
            delete StorageGoldAdd;
            delete StorageGoldRemove;
            delete StorageGoldIcon;
            delete StorageUpButton;
            delete StorageDownButton;
            delete StoragePositionBar;
            delete RanksSelectTextR;
            delete RanksSelectTextL;
            delete PointsLeft;
            delete RanksName;
            delete RanksSelectBox;
            delete RanksSaveName;
            delete UpButton;
            delete DownButton;
            delete PositionBar;
        }

        GuildRankOptions GetMyOptions();
        #pragma endregion

        #pragma region NoticePagePub
        bool NoticeChanged = true;
        long long LastNoticeRequest = 0;
        int NoticeScrollIndex = 0;
        MirButton *NoticeUpButton, *NoticeDownButton, *NoticePositionBar, *NoticeEditButton, *NoticeSaveButton;
        MirTextBox *Notice;
        #pragma endregion

        #pragma region MembersPagePub
        int MemberScrollIndex = 0, MembersShowCount = 1;
        MirButton *MembersUpButton, *MembersDownButton, *MembersPositionBar;
        MirLabel *MembersHeaderRank, *MembersHeaderName, *MembersHeaderStatus, *MembersShowOffline;
        MirButton *MembersShowOfflineButton;
        MirImageControl *MembersShowOfflineStatus;
        std::vector<MirDropDownBox*> MembersRanks;
        std::vector<MirLabel*> MembersName, MembersStatus;
        std::vector<MirButton*> MembersDelete;
        int MemberPageRows = 18;
        bool MembersShowOfflinesetting = true;
        #pragma endregion

        #pragma region StatusPagePub
        MirLabel *StatusLevelLabel;
        MirLabel *StatusHeaders;
        MirLabel *StatusGuildName, *StatusLevel, *StatusMembers;
        MirImageControl *StatusExpBar;
        MirLabel *StatusExpLabel, *RecruitMemberLabel;
        MirTextBox *MembersRecruitName;
        MirButton *RecruitMemberButton;
        #pragma endregion

        #pragma region StoragePagePub
        MirLabel *StorageGoldText;
        MirButton *StorageGoldAdd, *StorageGoldRemove, *StorageGoldIcon;
        std::vector<MirItemCell*> StorageGrid;
        MirButton *StorageUpButton, *StorageDownButton, *StoragePositionBar;
        int StorageIndex = 1;
        #pragma endregion

        #pragma region RankPagePub

        MirLabel *RanksSelectTextR, *RanksSelectTextL, *PointsLeft;
        MirTextBox *RanksName;
        std::vector<MirImageControl*> RanksOptionsStatus;
        std::vector<MirButton*> RanksOptionsButtons;
        std::vector<MirLabel*> RanksOptionsTexts;
        MirDropDownBox *RanksSelectBox;
        MirButton *RanksSaveName, *UpButton, *DownButton, *PositionBar;
        #pragma endregion

        #pragma region BuffPagePub
        #pragma endregion

        #pragma region GuildUI
        GuildDialog();
        #pragma endregion

        void RequestBuff(unsigned char Id);

        GuildBuff *FindGuildBuff(int Index);

    private:
        void UpdatePositionBar();

        void PositionBar_OnMoving(std::any sender, MouseEventArgs *e);

        void BuffsPanel_MouseWheel(std::any sender, MouseEventArgs *e);

    public:
        void RefreshInterface();

        GuildBuffInfo *FindGuildBuffInfo(int Index);

        void RequestGuildBuffList();

        void UpdateActiveStats();

        void CreateHintLabel(unsigned char Id);

        #pragma region ButtonResets
        void ResetButtonStats();
        #pragma endregion

        #pragma region NoticeDialogCode
        #pragma region NoticeButtonStates
        void EditNotice();
        void NoticeChange(std::vector<std::string> &newnotice);
        #pragma endregion

        #pragma region AssholeNoticeScroller
        void UpdateNotice(bool forward = false);

    private:
        void UpdateNoticeScrollPosition();

        void NoticePositionBar_OnMoving(std::any sender, MouseEventArgs *e);
        void NoticePanel_MouseWheel(std::any sender, MouseEventArgs *e);

        void NoticePanel_KeyDown(std::any sender, KeyEventArgs *e);
        #pragma endregion
        #pragma endregion

        #pragma region MembersDialogCode
    public:
        void NewMembersList(std::vector<GuildRank*> &NewRanks);
        void RefreshMemberList();

        void MemberStatusChange(const std::string &name, bool online);

        void OnNewRank(int Index, int SelectedIndex);

        void AddMember();

        void DeleteMember(int Index);

        void UpdateMembers();
        void MembersShowOfflineSwitch();
        void MembersPositionBar_OnMoving(std::any sender, MouseEventArgs *e);
    private:
        void UpdateMembersScrollPosition();
        void MembersPanel_MouseWheel(std::any sender, MouseEventArgs *e);

        void MembersPanel_KeyDown(std::any sender, KeyEventArgs *e);
        #pragma endregion

        #pragma region StatusDialogCode
        void StatusExpBar_BeforeDraw(std::any sender, EventArgs *e);
        #pragma endregion

        #pragma region RankDialogCode
    public:
        void NewRankRecieved(GuildRank *New);
        void MyRankChanged(GuildRank *New);
        void RankChangeRecieved(GuildRank *New);
        void UpdateRanks();
        void OnRankSelect(int Index);
        void SwitchRankOption(int OptionIndex);
        void RanksChangeName();
        void RanksName_KeyPress(std::any sender, KeyPressEventArgs *e);

        void RanksName_BeforeDraw();

        #pragma endregion

        #pragma region StorageCode

        void StoragePositionBar_OnMoving(std::any sender, MouseEventArgs *e);

    private:
        void StoragePanel_MouseWheel(std::any sender, MouseEventArgs *e);

        void StorageUpdatePositionBar();

    public:
        void UpdateStorage();

        void StorageAddGold();
        void StorageRemoveGold();
        #pragma endregion

        #pragma region UpdateNotice
        void RequestUpdateNotice();
        void RequestUpdateMembers();
        #pragma endregion

        #pragma region NoticeDialogPages
        void RightDialog(unsigned char Rpageid);
        void LeftDialog(unsigned char Lpageid);
        void StatusChanged(GuildRankOptions status);
        #pragma endregion

        #pragma region GuildDialogChecks

        void Show() override;
        #pragma endregion
    };
    class GuildBuffButton final : public MirControl
    {
    public:
        unsigned char Id = 0;
        //public MirButton Icon;
        MirImageControl *Icon;
        MirLabel *Name, *Info, *Obtained;
        //public MirControl HintLabel;

        virtual ~GuildBuffButton()
        {
            delete Icon;
            delete Name;
            delete Info;
            delete Obtained;
        }

        GuildBuffButton();

    protected:
        void OnMouseEnter() override;
        void OnMouseLeave() override;
    };
}
